// 虚拟dom生成函数  
/* 
  只出来三种情况
  1.{'div',{},'文字}
  2.{'div',{},[]}
  3.{'div',{},h()}
*/
import vnode from "./vnode"
export default function (sel,data,c){
  //检查参数
  if(arguments.length !==3) throw new Error("参数个数不对!");
  // 情况1
  if(typeof c === "string" || typeof c  === "number"){
    return vnode(sel,data,undefined,c,undefined)
  }
  // 情况2
  if(Array.isArray(c) && c.length>0){
    let children = []
    console.log(c)
    for(let child of c){
      // 是虚拟dom对象
      if(typeof child ==="object" && child.hasOwnProperty('sel')){
        children.push(child)
      }
    }
    return vnode(sel,data,children,undefined,undefined)

  }
  // 情况3
  if(typeof c === "object" &&  child.hasOwnProperty('sel')){
    let children = [c]
    return vnode(sel,data,children,undefined,undefined)
  }
  throw new Error('传入的参数不对!')
}